package com.lingCheng.avg.service.impl;

import antlr.StringUtils;
import com.lingCheng.avg.entity.AgvErrorInfo;
import com.lingCheng.avg.entity.AgvTasks;
import com.lingCheng.avg.entity.TaskChainPo;
import com.lingCheng.avg.mapper.AgvTasksMapper;
import com.lingCheng.avg.service.AgvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class AgvServiceImpl implements AgvService {
    @Autowired
    private AgvTasksMapper agvTasksMapper;

    /*
    * 根据状态查询对应任务
    * */
    @Override
    public List<AgvTasks> findRwState() {
        List<AgvTasks> agvTasks = agvTasksMapper.findList();
        return agvTasks;
    }


    /*
    * 根据任务表主键ID修改对应任务号
    * */
    @Override
    public void UpdateRWH(Long id, long rwh,int status) {
        agvTasksMapper.updateRWH(id,rwh,status);
    }

    @Override
    public void findBack(TaskChainPo taskChainPo) {
        AgvTasks agvTasks = agvTasksMapper.selectByRWCode(taskChainPo.getId());
        if (agvTasks!=null){
            agvTasksMapper.updateThisRW(taskChainPo);
        }
    }

    @Override
    public void getAgvErrorInfo(AgvErrorInfo errorInfo){

//        AgvErrorInfo agvError = agvTasksMapper.selectErrorInfoCount(errorInfo.getAmrId(),errorInfo.getMapId()
//                ,errorInfo.getOrderChainId(),errorInfo.getPoint(),errorInfo.getWarnId()
//                ,errorInfo.getWarnLevel());
//        if (agvError!=null){
//            if(agvError.getAmrName()!=null){
//                agvError.setUpdateTime(new Date());
//                agvTasksMapper.updateErrorInfo(agvError);
//            }else{
//                UUID uuid = UUID.randomUUID();
//                String id = uuid.toString().replace("-", "");
//                errorInfo.setId(id);
//                errorInfo.setUpdateTime(new Date());
//                agvTasksMapper.insertErrorInfo(errorInfo);
//            }
//        }else{
//            UUID uuid = UUID.randomUUID();
//            String id = uuid.toString().replace("-", "");
//            errorInfo.setId(id);
//            errorInfo.setUpdateTime(new Date());
//            agvTasksMapper.insertErrorInfo(errorInfo);
//        }
    }



}
